changed from CR question

http://codereview.stackexchange.com/a/63379/28156 credit to Rolfl