cleanup code
correct prototypes
rename some symbols to more suitable name