improved performance and made tests