Revised most of the code. It's better now