optimized variables declaration and added some documentation