Pull request to master

Noted, since this issue is similar to the one above I'll just respond here. I already separated the codes into different methods but I'll still see if I can improve it. :) Thanks for the advice.