Made the code more generic