Refactor: removed extraneous operations, rename some variables