Implemented part B, one small bug left though