Added some very basic input checks.
Removed duplicate utility functions I forgot to remove.