*Refactored DB code a bit
*FIxed bug where DeviceFactory wouldn't build devices with correct power
state