Following pseudo code on the book, added more implementation. However, it definitely won't work right now.