Fixes several issues