Refactors a bit
Fix some scenarios that resulted in undefined variables
Refactor and add some convenience methods