bug fix, code cleanup