updated as for ideas from http://stackoverflow.com/a/19168580/2003487