cleaned up implementation + added test