Modified by Dr. Michał Bleja and then Greg Carlin