Revamped the code