refactored the smartmeter a bit for better performance