Some error checking, moved about some variables, comments...