Added error output on error
Cleanup code
Added function to fetch user data
Added check for logged in or not