Port code from old Flex3 project