reconfigured to use datawarehouse model
fixed case sensitivity
refactored function