breaking code down for readability some more, updated demo