Moved parsing into a method. Better error checking.