implemented most functionality now - just needs testing