added advanced optimization and separated brepl