Refactored

Removed reduntent while loop