Refactored a chunk of spectql code, still not operational