code working, need to refactor and document