Limit data input and reduced scope of some variables.

Signed-off-by: Shido <the.keikun@gmail.com>