MODIFIED: total refactor.