Moved testing to the end of the script. Should be final version