added in some error checking and more verbose stuff