Refactor components using a dependency injector

This is just a quick rewrite. I need to rethink
the whole process again.