bunch of fixes and first attempt to allow calling function with references