Replaced hardcoded constants with macro headers, cleaned comments. Not tested.