Fixes several small bugs