Added tests and fixed design
fixed few issues found in real execution