Refactored init and self-test