Fixings and code decomposition

For purpose more clearly allocation of functions