fix implementation, with additional tests