Fixed bug introduced in the refactor, and several little improvements