Refactored

I made it a bit more idiomatic.