Refactor design pattern and cleanup