Fixes and Cleaning up

Was not tested, so it may contain errors.