added some tests + some optimizations