refactored and cleaned up for composer, fixed tests