Refactoring of canvas positioning code into it's own function to avoid repetition.