Got everything in place, rewritten to be easier to expand