improved debugging; fixed bracket parsing