added implementations for both functions
comments added