updated this bit to create the dir if it doesn't exist and use abspath.