ams package stuff
more concise version