Major rewrite to simplify