Works. Now to refactor and comment