Cleaning up the brush function. Working on optimizing performance.