fixed some tests and reuse some existing functions