Added cast from long to int for LAST_INSERT_ID() call