fixing more warnings and deduplicating code