Fix bug and improve on OS X