Fixed major performance bug + minor improvements