finally working again & cleanup code