Fixed some bugs with the migs integration, cleaned up some code