Fixes a few bugs