most functionality is here, QA needed