refuctoring & bugfix