Refactored. Added more sensible names and a simple Image class
Added some exception handling