Cleaning code

fixing some bugs