Fixed the code so that it now chains instead of being nested