some bug fixes

code cleanup!