Improved formatting, added sanity check