spc lib highly refactored