refactored a lot, implemented authorize process.