Bug fixes. Improve SP method gen