Rewrite to be more extendable