Improved null checks, closing streams and adding @Overrides