with some modifications on paperclip