Algorithm changes and exceptions added