Cleaned up code further especially wrt maxSd