fixed errors with implementation of sandberg's solution