Refactor code

- Use eager loading
- Require libs only if needed
- Split logic into multiple files