Proper fix

Also cleans up some other bad coding