Clean up the code & added type arguments