Fix various issues and cleanup whitespace