updated to check for vertical position and adjust accordingly