added EnergyProducer and a lot of code refactoring