Updated with unit tests