adding repay logic and some fixes


Signed-off-by: Yasen Yankov <iasen.iankov@gmail.com>