Major refactor of gAPI to make more generic and readable