Updated the code, will add some tests later.