Bug fixes and pretty print