Started rewriting some of the functions