Based on a program by Tobias Kolditz which can be found here