fixed some bugs from code cleanup