refactored cia code & fixed bugs