First, indent your code properly. This will make your code more readable, helping you to trace the flow of control through your program.

Then, you should tell us exactly how do the functions fail to work.