beginning refactor
Bug fixes, code optimization
bug fix