turned this code into a simple function
merging latest
Merge branch 'workinprogress'