Refactor API into namespace