Working version of code

Removed debug info.
Still needs improvements. (cosmetic, error handling)