Improved formatting, fixed order of ops that was causing a segfault