Cleaner code, other optimizations before changes