Cleaned up the code and added return codes
Cleaned up the code and added return codes