Apply some fixes for integration of code by virgil