Code refactor and munit changes