Very rough initial implementation. Needs to be tweaked for more realistic behaviour later. thanks to Greg Brill for pointers on this.