bug fix + code cleanup