Implement left factoring

I've done my best to write clean code and test it to a reasonable extent. Hopefully I haven't made to many beginners mistakes...