finally made the code right with regression testing