Just some code cleaning

Just cleaned up the code, did some bug fixed etc.