simplified the code big time, need more fault protection