refactored updateBuffer to be more intuitive and less redundant