Add some documentation and improve formatting