Refactoring, cleaning unused variables, changing assertion for exception raising, removing trailling whitespace