Completed image load function, works and debugged