updates from https://gist.github.com/dcondrey/f1187c2f7f51ed8daf85