fixing 'ctx not defined' bug