More code will not solve your problem. Better understanding will.