Made the code generic