implemented cache and other minor things, needs to be tested