implemented most functionality