made canvas function and added some comments