Fixed SCI-1296, added code for edge cases