added implementation for third assignment