* removed unused var
* synchronize the code of two similar functions
* moved some #defines to where they belong