Refactor some things and dispose properly