Updated implementation + wrote some tests