Added more error detection to verify arguments. Added appropriate unit tests.