Fixed small bug
misc format + efficiency changes