Added better multi-threading support, changed orientation and cleaned up code.