Fixed some bugs I've introduced during refactorting. :(