Fixed declarations and minor improvements