Minor formatting changes throughout
Added some error checking to main and associated functions