Fix some issues and apply some suggested patches