cleanup code, added premultiplier option
renamed some functions to be more obvious