refactored, few additions, draft version