Various fixes and cleanup