Refactored things a little bit to make the flow clearer
fixed tabs to make Pieter happy