Fix for code ordering related bugs