Reorganizing the code

Still there are some changes to make. feeling like code still looking
ugly need to get it reviewed