Originally by Daniel Stocks, but github repo has vanished