Refactor, made constant for image size and fixed catch clauses