After refactoring.. still not complete.
first working verion! hurray!