improved the code