GAIA functions refactor and code cleanup