bug fixes + added test