partial cleanup of target image size error checking
rearranged code a bit to make it easier to run theano-only version