Added extensive error checking. These have a few TODO list items on them, but should function for base conditions.