Added some status checking code. This is not generic to all chips so it should be revisited. Updated program to use new functions better.