Moving code to canvas