bug fix, some cleanup