Revert "Fixes some bugs I introduced"

This reverts commit badef914efde6437f8d3a9c895f3edae51c57752.
Revert "Revert "Fixes some bugs I introduced""

This reverts commit d51a457e0f263246cb01f98f54ef89464e828136.