rearrange some things
remove unused vars