main logic written, but not tested