basic logic fully implemented (not tested)