fixed bug in S
added tests for s