Major rewrite to account for more situations, non functional atm