Added stable implementation of second part of fourth assignment