Cleaned up code to pass in all necessary parameters