Changed into a class and added decoding method