Mostly working code for storing positions