Adding more code from my old firebird project. Need a break
Adapted for color reference/return issues.