Condensed the entire thing down to functions.