This needs some more manual testing and adding unit testing Change-Id: Iadfe3cf7927d5318f89ba17f067000f9399060af