merged with patch from evanbeard / delayed_paperclip