Fleshed-out implementation. And cut-out redundant code.