Fixes bugs in last commit