Fixes some bugs