Added tests + some fixes