fixing some issues as per @dkua's recommendation