finished implementing the todos and fixed original code