Refactored code to follow trezor-common structures