Cleaning up, refactoring, tests added

Signed-off-by: Yakov Goldberg <yakov.g@samsung.com>