Fixed one small bug and did code cleanup