First quick version.
Refactored.