Fixed the code and reduced redunded code