Updated implementation. Final for handing in..