Changed structure of code and data to make it more flexible and clear.