removed useless IMAGES variable and tidied up the code a bit