fixed valgrind errors, image loading works in a more sensible way now