This work proposes an improved peridynamics density-based topology optimization framework for compliance minimization. One of the main advantages of using a peridynamics discretization relies in the fact that it provides a consistent regularization of classical continuum mechanics into a nonlocal continuum, thus containing an inherent length scale called the horizon. Furthermore, this reformulation allows for discontinuities and is highly suitable for treating fracture and crack propagation. Partial differential equations are rewritten as integrodifferential equations and its numerical implementation can be straightforwardly done using meshfree collocation, inheriting its advantages. In the optimization formulation, Solid Isotropic Material with Penalization (SIMP) is used as interpolation for the design variables. To improve the peridynamic formulation and to evaluate the objective function in a energetically consistent manner, surface correction is implemented. Moreover, a detailed sensitivity analysis reveals an analytical expression for the objective function derivatives, different from an expression commonly used in the literature, providing an important basis for gradient-based topology optimization with peridynamics. The proposed implementation is studied with two examples illustrating different characteristics of this framework. The analytical expression for the sensitivities is validated against a reference solution, providing an improvement over the referred expression in the literature. Also, the effect of using the surface correction is evidenced. An extensive analysis of the horizon size and sensitivity filter radius indicates that the current method is mesh-independent, i.e. a sensitivity filter is redundant since peridynamics intrinsically filters length scales with the horizon. Different optimization methods are also tested for uncracked and cracked structures, demonstrating the capabilities and robustness of the proposed framework.