Improve tests and fix pixel assignment bug