Add healthcheck api, refactor code and cleanup