added existing code and tests