Cleaned unused imports, used try-with-resource to ensure resources get closed where applicable