fixed some bugs introduced in the previous refactor