Updated version with moar tests and minor fix