Remove Duplicate Code, Add Unit Tests, Fix Failing Tests

This fixes Issue #63