Convert nested functions into methods

Signed-off-by: Daniele Ricci <daniele.athome@gmail.com>