remove duplication in quickmagick code