Some code cleanup & fixed problem of used bdefore definitions