Fixed performance bug with inplace algorithm