Refactor a bit
Write some comments